feat: add apify api subcommand for direct API access#1076
feat: add apify api subcommand for direct API access#1076patrikbraborec wants to merge 5 commits intomasterfrom
apify api subcommand for direct API access#1076Conversation
Add a general-purpose authenticated HTTP client for the Apify API, similar to `gh api` in GitHub CLI. Supports GET/POST/PUT/PATCH/DELETE methods, request body (including stdin), custom headers, and a --list-endpoints flag powered by the bundled OpenAPI spec. Closes #1075 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Add missing `return` after `printHelp()` to prevent fetch with undefined endpoint - Make build resilient to network failures by falling back to committed api-endpoints.json - Commit api-endpoints.json so fresh checkouts work without network access - Wrap test cleanup in try/finally to prevent actor leak on assertion failure Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…y params, and lint fix Add support for positional HTTP method syntax (e.g. `apify api GET /v2/users/me`), auto-prepend `v2/` prefix when omitted, add `--params` flag for query parameters, use `getLoggedClientOrThrow` for auth, switch to `simpleLog` for output, validate JSON body before sending, and fix prefer-destructuring lint error. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Tighten input validation in `apify api`: extract parseParams/parseHeaders helpers, support multi-header JSON form, reject nested/non-scalar query params, and detect conflicts between the positional HTTP method and the --method flag. Derive the base URL from apifyClient.baseUrl so the v2 prefix and APIFY_CLIENT_BASE_URL are handled in one place, and hint at --list-endpoints on 404 responses. Register the command in the docs generator (and regenerate docs). Move fetch-api-endpoints out of `build` into `prepack` so local builds do not require network access. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1ab31a3 to
3ab62dd
Compare
useConsoleSpy sets restoreMocks: false, so spy.mock.calls accumulates across tests. Reading calls[0][0] returned the first test's v2/users/me response on every subsequent test — passing by coincidence when checking .data.id/.username, failing when checking .data.items or .data.name. Switch to logMessages.log[0], which resets per test. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
| required: false, | ||
| stdin: StdinMode.Stringified, | ||
| }), | ||
| header: Flags.string({ |
There was a problem hiding this comment.
Please make an issue to support array options (so you can do -H XX:YY -H ZZ:AA)
| "build": "yarn clean && tsc && tsup", | ||
| "build-bundles": "bun run scripts/build-cli-bundles.ts", | ||
| "prepack": "yarn insert-cli-metadata && yarn build && yarn update-docs", | ||
| "prepack": "yarn insert-cli-metadata && (yarn fetch-api-endpoints || echo 'Warning: Failed to fetch API endpoints, using existing file') && yarn build && yarn update-docs", |
There was a problem hiding this comment.
Failing to fetch this should prevent building!! Also i would NOT bundle this in our code but rather download it on demand when listing endpoints
l2ysho
left a comment
There was a problem hiding this comment.
No other concern except of one Vlad pointed to, about download of endpoints list on demand. Maybe we can cache it in some clever way? cc @vladfrangu
|
Ok, I would probably go with a call fetch API endpoints when user/agent calls |
|
Lets go for downloading on demand for now, and in the future we can probably have an fs cache (but not bundling it in CLI) |
Summary
Adds
apify api— a general-purpose authenticated HTTP client for the Apify API, inspired bygh api.apify api v2/users/me— make authenticated GET requestsapify api v2/acts --method POST --body '{...}'— create resourcesapify api --list-endpoints— browse all 129 API endpoints (from bundled OpenAPI spec)Features
--method/-X(GET, POST, PUT, PATCH, DELETE)--body/-d(JSON string or stdin with-)--header/-H--list-endpoints/-l— lists all available endpoints with color-coded methods and descriptions, powered by the Apify OpenAPI spec fetched at build timeCloses #1075
🤖 Generated with Claude Code